package com.reform.config;

import com.reform.exception.MyException;
import com.reform.res.Result;
import com.reform.res.ResultCode;
import io.lettuce.core.RedisException;
import lombok.extern.log4j.Log4j;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

// package exception
@ControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 捕获业务异常
     * @param ex
     * @return
     */
    @ExceptionHandler(MyException.class)
    @ResponseBody
    public Result handleBusinessException(Exception ex) {
        return Result.failure(ResultCode.USER_HASNOT_LOGIN);
    }

    /**
     * 捕获其他异常
     * @param ex
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result handleException(Exception ex) {
        ex.printStackTrace();
        return Result.failure(ResultCode.OTHER_ERROR,ex.getMessage());
    }
}
